/**
 * 
 */
package com.how2java.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.how2java.pojo.User;
import com.how2java.service.UserService;

/**
 * @author LMH
 * @version 创建时间：2019年5月6日 下午3:27:23
 */
@Controller
@RequestMapping("/U")
public class UserController {

	@Autowired
	UserService userService;
	
	@RequestMapping(value="/user/{id}",method=RequestMethod.GET)
	@ResponseBody   //作用是将 java对象转为json格式的数据
	public Integer editCategory(User user){
//		System.out.println("--->>"+user.getId());
		User u= userService.get(user.getId());
		System.out.println("name--->>"+u.getName());
		System.out.println("age--->>"+u.getAge());
//		ModelAndView mav = new ModelAndView("editCategory");
//		mav.addObject("u", u);
//		return mav;
		Map all = userService.getAll(user.getId());
		System.out.println(all.get("id"));
		System.out.println(all.get("name3"));
		System.out.println(all.get("age"));
		System.out.println(all.get("name2"));
//		return u.getId();
		return 1;
	}	
	
	@RequestMapping(value="/user2/{age}",method=RequestMethod.GET)
	@ResponseBody   //作用是将 java对象转为json格式的数据
	public List<Map> test(User user){
		System.out.println(user.getAge());
//		Map<Integer, Map> map = userService.getMore(user.getAge());
//		System.out.println(map.get(key));
		List<Map> list = userService.getMore(user.getAge());
		for (int i = 0; i < list.size(); i++) {
			System.out.println(list.get(i).get("id"));
			System.out.println("name--->>"+list.get(i).get("name"));
			System.out.println(list.get(i).get("name2"));
		}
		return list;
	}	
}
